/*
 * MockChannelFacade.java    0.0.1    19/set/2009
 * 
 * Copyright (c) 2009 mentalsmash.org
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * The use of the Apache License does not indicate that this project is
 * affiliated with the Apache Software Foundation.
 */ 
package org.mentalsmash.tazio.net.cs.server.impl.mock;

import java.nio.channels.SelectionKey;

import org.mentalsmash.tazio.net.cs.server.ProtocolHandler;
import org.mentalsmash.tazio.net.cs.server.impl.BufferPool;
import org.mentalsmash.tazio.net.cs.server.impl.ByteBufferInputQueue;
import org.mentalsmash.tazio.net.cs.server.impl.ByteBufferOutputQueue;
import org.mentalsmash.tazio.net.cs.server.impl.ChannelFacade;
import org.mentalsmash.tazio.net.cs.server.impl.InputQueue;
import org.mentalsmash.tazio.net.cs.server.impl.OutputQueue;


/**
 * Mock channel facade, used for testing purposes
 * @version    0.0.1    19/set/2009    
 * @author     Andrea Reale <andrea.reale@gmail.com>
 */
public class MockChannelFacade implements ChannelFacade {

	private final ByteBufferInputQueue input;
	private final ByteBufferOutputQueue output;
	
	public MockChannelFacade(BufferPool pool) {
		input = new ByteBufferInputQueue(pool);
		this.output = new ByteBufferOutputQueue(pool, this);
	}
	@Override
	public InputQueue getInputQueue() {
		return input;
	}

	/* (non-Javadoc)
	 * @see org.mentalsmash.tazio.net.cs.server.ChannelFacade#getInterestOps()
	 */
	/**
	 * Always returns SelectionKey.OP_READ & SelectionKey.OP_WRITE
	 */
	@Override
	public int getInterestOps() {
		return SelectionKey.OP_READ & SelectionKey.OP_WRITE;
	}

	/* (non-Javadoc)
	 * @see org.mentalsmash.tazio.net.cs.server.ChannelFacade#getOutputQueue()
	 */
	@Override
	public OutputQueue getOutputQueue() {
		return output;
	}

	/* (non-Javadoc)
	 * @see org.mentalsmash.tazio.net.cs.server.ChannelFacade#modifyInterestOps(int, int)
	 */
	/**
	 * No-Op
	 */
	@Override
	public void modifyInterestOps(int opsToAdd, int opsToRemove) {
		// no-op

	}

	/* (non-Javadoc)
	 * @see org.mentalsmash.tazio.net.cs.server.ChannelFacade#setProtocolHandler(org.mentalsmash.tazio.net.cs.server.ProtocolHandler)
	 */
	/**
	 * No-Op
	 */
	@Override
	public void setProtocolHandler(ProtocolHandler handler) {
		//no-op

	}
	/* (non-Javadoc)
	 * @see org.mentalsmash.tazio.net.cs.server.ChannelFacade#isReadable()
	 */
	@Override
	public boolean isReadable() {
		return true;
	}
	/* (non-Javadoc)
	 * @see org.mentalsmash.tazio.net.cs.server.ChannelFacade#isWritable()
	 */
	@Override
	public boolean isWritable() {
		return true;
	}

}
